<template>
  <div class="borad">
    <span v-for="num of nums" class="number" @click="inputNum(num)">{{
      num
    }}</span>
    <span class="dot" @click="inputDot('.')">.</span>
    <span class="number" @click="inputO(0)">0</span>
    <span class="delete" @click="inputDelete">
      <SvgIcon icon-class="delete"></SvgIcon>
    </span>
  </div>
</template>

<script setup lang="ts">
const emit = defineEmits(["input"]);
const nums: Array<number> = [7, 8, 9, 4, 5, 6, 1, 2, 3];
let input_content: Array<string> = ["0"];
const inputNum = (num: number | string) => {
  if (input_content.length >= 10) return;
  if (input_content[0] == "0" && input_content.length == 1) {
    input_content.pop();
  }
  input_content.push(String(num));
  emit("input", input_content.join(""));
};
const inputDot = (num: number | string) => {
  if (input_content.length >= 10) return;
  if (input_content[input_content.length - 1] == ".") return;
  input_content.push(String(num));
  emit("input", input_content.join(""));
};
const inputO = (num: number | string) => {
  if (input_content.length >= 10) return;
  if (input_content[0] == "0" || input_content[input_content.length - 1] == "0")
    return;
  input_content.push(String(num));
  emit("input", input_content.join(""));
};
const inputDelete = () => {
  input_content.pop();
  if (input_content.length == 0) {
    input_content.push("0");
  }
  emit("input", input_content.join(""));
};
</script>

<style lang="scss">
.borad {
  margin-top: 0.8em;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  .number,
  .dot {
    font-size: 2em;
    text-align: center;
    padding: 0.4em 0;
    color: #8a8a8a;
    position: relative;
  }
  .delete {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 2em;
      height: 2em;
    }
  }
}

/*动画*/
.number::after,
.dot::after {
  position: absolute;
  content: " ";
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: 0;
  height: 0;
  margin: auto;
  border-radius: 50%;
  background: rgba(138, 138, 138, 0.103);
}

.number:hover,
.dot:hover {
  &::after {
    animation-name: lianyi;
    animation-duration: 0.3s;
    animation-timing-function: ease-in-out;
    animation-delay: 0s;
    animation-direction: alternate;
    animation-iteration-count: 1;
    animation-play-state: running;
  }
}
@keyframes lianyi {
  0% {
    width: 0em;
    height: 0em;
  }
  100% {
    width: 2em;
    height: 2em;
  }
}
</style>
